import type {
  MenuInfoPlain,
  MenuPlainListResp,
  RoleMenuResp,
} from './model/menuModel';

import type { BaseDataResp, BaseIDReq, BaseResp } from '#/api/model/baseModel';

import { requestClient } from '#/api/request';

enum Api {
  /**
   * @author Buke
   * @todo-needfix 不标准接口名称，待修改
   */
  CreateMenu = '/sys-api/role/create',
  DeleteRole = '/sys-api/role/delete',
  GetMenuById = '/sys-api/menu',
  GetMenuListByRole = '/sys-api/menu/role/list',
  GetRoleDetail = '/sys-api/role/info',
  GetRoleList = '/sys-api/role/list',
  UpdateRole = '/sys-api/role/update',
}

/**
 * @description: Get user menu list by role id
 */

export const getMenuListByRole = () => {
  return requestClient.get<BaseDataResp<RoleMenuResp>>(Api.GetMenuListByRole);
};

/**
 * @description: Get Role list
 */

export const getRoleList = (params: any) => {
  return requestClient.get<BaseDataResp<MenuPlainListResp>>(Api.GetRoleList, {
    params,
  });
};
/**
 * @description: Get role detail
 */

export const getRoleDetail = (id: any) => {
  return requestClient.get<BaseDataResp<MenuPlainListResp>>(
    `${Api.GetRoleDetail}/${id}`,
  );
};

/**
 *  @description: Create a new role
 */
export const createRole = (params: MenuInfoPlain) => {
  return requestClient.post<BaseResp>(Api.CreateMenu, params);
};

/**
 *  @description: Update the menu
 */
export const updateRole = (params: MenuInfoPlain) => {
  return requestClient.put<BaseResp>(Api.UpdateRole, params);
};

/**
 *  @description: Delete menus
 */
export const deleteRole = (id: number) => {
  return requestClient.delete<BaseResp>(`${Api.DeleteRole}/${id}`);
};

/**
 *  @description: Get menu By ID
 */
export const getMenuById = (params: BaseIDReq) => {
  return requestClient.get<BaseDataResp<MenuInfoPlain>>(Api.GetMenuById, {
    params,
  });
};
